#!/bin/bash

set -e

APP_NAME="sloth-bear"
APP_HOST="liufq.cn"

git pull

echo "开始构建前端..."
cd ../../sloth-bear-web
npm run build

echo "开始构建后端..."
cd ../sloth-bear-server
mvn clean package -DskipTests

echo "开始部署..."
cd ..
sshpass -p ${LFQ_PASS} ssh root@${APP_HOST} 'rm -rf /opt/sloth-bear && mkdir -p /opt/sloth-bear'
sshpass -p ${LFQ_PASS} scp -r ops/deploy/* root@${APP_HOST}:/opt/sloth-bear/

sshpass -p ${LFQ_PASS} scp -r sloth-bear-web/dist root@${APP_HOST}:/opt/sloth-bear/
sshpass -p ${LFQ_PASS} scp sloth-bear-server/target/sloth-bear.jar root@${APP_HOST}:/opt/sloth-bear/

sshpass -p ${LFQ_PASS} ssh root@${APP_HOST} 'cd /opt/sloth-bear && docker-compose up -d --build --force-recreate'
echo "部署完成"